/**
 * @file   1016.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sun Jul 18 02:57:59 2021
 * 
 * @brief  PAT advanced 1016:Phone Bills
 * 
 * 
 */
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<iomanip>
using namespace std;
class info;
bool cmp(info& I1,info& I2);//usage:Sort the information sequence!
bool cmp2(info& I1,info& I2);//usage:compare the time variable!
void gettime(info& I);//Output the time information
int during(info& I1,info& I2);//Output the dure time!
class info{
public:
    int month;
    int day;
    int hour;
    int minute;
    bool type;//1 means on-line and 0 means off-line
};
class Solution{
private:
    map<string,vector<info>> calls;
    int questnum;
    vector<int> costperhour;
    map<string,double> thecost;
public:
    Solution();//Constructer:Initialize
    void solve();//Solve the problem for each people
    double output(info& I1,info& I2);//Output the result.
    double calculatemoney(info& I1,info& I2);//Output the phone bill!
    bool check(string name){//check output or not!
	vector<info> Inf=calls[name];
	for(int i=0;i<Inf.size()-1;i++){
	    if(Inf[i].type==true&&Inf[i+1].type==false){
		return true;
	    }
	}
	return false;
    }
};
Solution::Solution(){
    for(int i=0;i<24;i++){
	int d;
	cin>>d;
	costperhour.push_back(d);
    }
    cin>>questnum;
    for(int i=0;i<questnum;i++){
	string name;
	cin>>name;
	info I;
	int M,d,h,m;//M:month,d:day,h:hour,m:minute!
	scanf("%d:%d:%d:%d",&M,&d,&h,&m);
	I.month=M;
	I.day=d;
	I.hour=h;
	I.minute=m;
	string T;//on-line or off-line
	cin>>T;
	if(T=="on-line"){
	    I.type=true;
	}else{
	    I.type=false;
	}
	calls[name].push_back(I);
    }
    for(auto it=calls.begin();it!=calls.end();it++){
	sort(it->second.begin(),it->second.end(),cmp);
    }
}
bool cmp(info& I1,info& I2){
    if(I1.day<I2.day){
        return true;
    }
    else if(I1.day==I2.day){
        if(I1.hour<I2.hour){
	    return true;
	}
        else if(I1.hour==I2.hour){
	    if(I1.minute<I2.minute){
	        return true;
	    }
	}
    }
    return false;    
}
void Solution::solve(){
    for(auto it=calls.begin();it!=calls.end();it++){
	vector<info> Nowinf=it->second;
	if(check(it->first)==false){
	    continue;
	}
	cout<<it->first<<" ";
	if(Nowinf[0].month<10){
	    cout<<"0";
	}
	cout<<Nowinf[0].month<<endl;
	for(int i=0;i<Nowinf.size()-1;i++){
	    if(Nowinf[i].type==true){
		if(Nowinf[i+1].type==false){//Pair!
		    thecost[it->first]=thecost[it->first]+output(Nowinf[i],Nowinf[i+1]);
		}
	    }
	}
	cout<<"Total amount: $"<<fixed<<setprecision(2)<<thecost[it->first]<<endl;
    }
}
void gettime(info& I){
    if(I.day<10){
	cout<<"0";
    }
    cout<<I.day<<":";
    if(I.hour<10){
	cout<<"0";
    }
    cout<<I.hour<<":";
    if(I.minute<10){
	cout<<"0";
    }
    cout<<I.minute;
}
int during(info& I1,info& I2){
    int d=I2.day-I1.day;
    int h=I2.hour-I1.hour;
    int m=I2.minute-I1.minute;
    int dure=d*24*60+h*60+m;
    return dure;
}
double Solution::calculatemoney(info& I1,info& I2){
    int d1=I1.day;
    int h1=I1.hour;
    int m1=I1.minute;
    int d2=I2.day;
    int h2=I2.hour;
    int m2=I2.minute;
    double money=0;
    money=money+m2*costperhour[h2]-m1*costperhour[h1];//Handle the minutes(less than one-hour part)
    if(d1==d2){//On one single day!
	for(int i=h1;i<h2;i++){
	    money=money+costperhour[i]*60;
	}
    }else{
	int totalcost=0;
	for(int i=0;i<24;i++){
	    totalcost=totalcost+costperhour[i]*60;
	}
	for(int i=h1;i<24;i++){
	    money=money+costperhour[i]*60;
	}
	for(int i=0;i<h2;i++){
	    money=money+costperhour[i]*60;
	}
	money=money+totalcost*(d2-d1-1);
    }
    money=money*1.0/100;
    return money;
}
double Solution::output(info& I1,info& I2){
    gettime(I1);
    cout<<" ";
    gettime(I2);
    double money=calculatemoney(I1,I2);
    cout<<" "<<during(I1,I2)<<" $"<<fixed<<setprecision(2)<<money<<endl;
    return money;
}
int main(){
    Solution S;
    S.solve();
}
